home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / BoxMaker++ / BoxMaker++ ƒ / sources / boxmakergetfile.cp < prev    next >
Encoding:
Text File  |  1995-06-14  |  4.2 KB  |  168 lines  |  [TEXT/KAHL]

  1.  
  2. #include <Aliases.h>
  3. #include <Finder.h>
  4. #include <StandardFile.h>
  5.  
  6. #include "standardgetfile.h"
  7. #include "boxmakergetfile.h"
  8.  
  9. #define sfItemSelectThisItem    10
  10.  
  11. boxmakergetfile::boxmakergetfile( short dlogID)
  12.     : standardgetfile( dlogID)
  13. {
  14.     Handle theTypesHandle = Get1Resource( 'typs', 128);
  15.     if( theTypesHandle != 0)
  16.     {
  17.         HLock( theTypesHandle);
  18.             changeTypes( (OSType *)*theTypesHandle, GetHandleSize( theTypesHandle) >> 2);
  19.         HUnlock( theTypesHandle);
  20.         ReleaseResource( theTypesHandle);
  21.     }
  22.     //
  23.     // This handle will never get freed again. This is no problem,
  24.     // since it are only allocated once, and would only be freed at exit
  25.     // time, anyway.
  26.     //
  27.     Handle theTypeCreatorPairsHandle = Get1Resource( 'tycr', 128);
  28.     if( theTypeCreatorPairsHandle == 0)
  29.     {
  30.         numTypeCreatorPairs = -1;
  31.         theTypeCreatorPairs = 0L;
  32.     } else {
  33.         MoveHHi( theTypeCreatorPairsHandle);
  34.         HLock( theTypeCreatorPairsHandle);
  35.         numTypeCreatorPairs = GetHandleSize( theTypeCreatorPairsHandle) >> 2;
  36.         theTypeCreatorPairs = (OSTypePair *)*theTypeCreatorPairsHandle;
  37.     }
  38.     //
  39.     // read extra flags:
  40.     //
  41.     Handle flagHandle = Get1Resource( 'flgs', 128);
  42.     if( flagHandle)
  43.     {
  44.         const Boolean *flags = (const Boolean *)*flagHandle;
  45.         enterFolders    = flags[ 0];
  46.         passFolders     = flags[ 1];
  47.         enterInvisibles = flags[ 2];
  48.         passInvisibles  = flags[ 3];
  49.         ReleaseResource( flagHandle);
  50.     } else {
  51.         enterFolders    = false;
  52.         passFolders     = false;
  53.         enterInvisibles = false;
  54.         passInvisibles  = false;
  55.     }
  56.     allowFolderSelection = passFolders || enterFolders;
  57.     selectThisItemControl = 0L;
  58. }
  59.  
  60. Boolean boxmakergetfile::matchesTypeList( OSType ourType) const
  61. {
  62.     Boolean result = (numTypes == -1);
  63.  
  64.     OSType *theType = theTypes;
  65.     
  66.     for( int i = 0; i < numTypes; i++)
  67.     {
  68.         if( ourType == *theType)
  69.         {
  70.             result = true;
  71.             break;
  72.         }
  73.     }
  74.     return result;
  75. }
  76.  
  77. Boolean boxmakergetfile::matchesTypeCreatorPairs(
  78.                                     OSType theType, OSType theCreator) const
  79. {
  80.     Boolean result = (numTypeCreatorPairs == -1);
  81.  
  82.     OSTypePair *thePair = theTypeCreatorPairs;
  83.     
  84.     for( int i = 0; i < numTypeCreatorPairs; i++)
  85.     {
  86.         if( matches( theType, thePair->type) && matches( theCreator, thePair->creator))
  87.         {
  88.             result = true;
  89.             break;
  90.         }
  91.     }
  92.     return result;
  93. }
  94.  
  95. Boolean boxmakergetfile::filterThisItem( const CInfoPBPtr myPB)
  96. {
  97.     const Boolean invisible = ((myPB->hFileInfo.ioFlFndrInfo.fdFlags & fInvisible) != 0);
  98.     const Boolean folder    = ((myPB->hFileInfo.ioFlAttrib & ioDirMask) != 0);
  99.     
  100.     Boolean result = invisible && !passInvisibles;
  101.     //
  102.     // we do not check for 'passFolders'; folders must be visible in
  103.     // the dialog at any time.
  104.     //
  105.     if( (result == false) && !folder)
  106.     {
  107.         result = !matchesTypeCreatorPairs(
  108.                         myPB->hFileInfo.ioFlFndrInfo.fdType,
  109.                         myPB->hFileInfo.ioFlFndrInfo.fdCreator);
  110.     }
  111.     return result;
  112. }
  113.  
  114. short boxmakergetfile::handleItemPress( short item, DialogPtr theDialog)
  115. {
  116.     //
  117.     // CustomGetFile calls the dialog hook for both main and subsidiary dialog boxes.
  118.     // Make sure that dialog record indicates that this is the main GetFolder dialog.
  119.     //
  120.     // 950530 RV: work around a bug in SC++ 8.0. When 'enums are always ints' is off
  121.     // character constants such as 'stdf' are treated as shorts.
  122.     //
  123.     #ifdef THINK_C
  124.         if( (OSType)(((WindowPeek)theDialog)->refCon) == 'stdf')
  125.     #else
  126.         if( (OSType)(((WindowPeek)theDialog)->refCon) == sfMainDialogRefCon)
  127.     #endif
  128.     {
  129.         //
  130.         // Disable the 'Select this one' button when needed:
  131.         //
  132.         if( selectThisItemControl != 0)
  133.         {
  134.             const short hilite = ((sfFile.name[ 0] == 0)
  135.                         || ((sfIsFolder || sfIsVolume) && !allowFolderSelection)) ? 255 : 0;
  136.  
  137.             HiliteControl( selectThisItemControl, hilite);
  138.         }
  139.         switch( item)
  140.         {
  141.             case sfHookFirstCall:
  142.                 {
  143.                     short    itemType;
  144.                     Rect    itemRect;
  145.                     
  146.                     GetDialogItem( theDialog, sfItemSelectThisItem, &itemType,
  147.                             (Handle *)&selectThisItemControl, &itemRect);
  148.                 }
  149.                 break;
  150.  
  151.             case sfHookLastCall:
  152.                 selectThisItemControl = 0L;
  153.                 break;
  154.  
  155.             case sfItemSelectThisItem:
  156.                 //
  157.                 // If the user clicked the select current button, force a cancel and
  158.                 // set the sfGood field of the Reply record to true, unless nothing
  159.                 // is selected or a folder is selected and passFolders is false.
  160.                 //
  161.                 item = sfItemCancelButton;
  162.                 sfGood = true;
  163.                 break;
  164.         }
  165.     }
  166.     return item;
  167. }
  168.